home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / pascal / swag / memory.swg / 0037_FILL Memory Routines.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-21  |  2.5 KB  |  85 lines

  1. UNIT Fill;
  2. (**) INTERFACE (**)
  3.   PROCEDURE FillWord(VAR Dest; Count, What : Word);
  4.   PROCEDURE FillOthr(VAR Dest; Count : Word; What : Byte);
  5.   PROCEDURE FillPatt(VAR Dest, Patt; Count, Siz : Word);
  6.   PROCEDURE FillPattOthr(VAR Dest, Patt; Count,
  7.               Siz : Word);
  8.  
  9. (**) IMPLEMENTATION (**)
  10.   PROCEDURE FillWord(VAR Dest; Count, What : Word);
  11.               Assembler;
  12.   ASM
  13.     LES DI, Dest    {ES:DI points to destination}
  14.     MOV CX, Count   {count in CX}
  15.     MOV AX, What    {word to fill with in AX}
  16.     CLD             {forward direction}
  17.     REP STOSW       {perform the fill}
  18.   END;
  19.  
  20.   PROCEDURE FillOthr(VAR Dest; Count : Word; What : Byte);
  21.               Assembler;
  22.   ASM
  23.     LES DI, Dest    {ES:DI points to destination}
  24.     MOV CX, Count   {count in CX}
  25.     MOV AL, What    {byte to fill with in AL}
  26.     CLD             {forward direction}
  27.     @TheLoop:
  28.     STOSB           {store one byte}
  29.     INC DI          {skip one byte}
  30.     Loop @TheLoop
  31.   END;
  32.  
  33.   PROCEDURE FillPatt(VAR Dest, Patt; Count, Siz : Word);
  34.               Assembler;
  35.   ASM
  36.     MOV CX, Siz
  37.     JCXZ @Out
  38.     XCHG CX, DX     {size of pattern in DX}
  39.     MOV CX, Count   {count in CX}
  40.     JCXZ @Out
  41.     PUSH DS
  42.     LES DI, Dest    {ES:DI points to destination}
  43.     LDS SI, Patt    {DS:SI points to pattern}
  44.     MOV BX, SI      {save SI in BX}
  45.     CLD             {forward direction}
  46.     @PatLoop:
  47.       PUSH CX         {save count for outer loop}
  48.       MOV CX, DX      {put inner count in CX}
  49.       MOV SI, BX      {DS:SI points to source}
  50.       REP MOVSB       {make one copy of pattern}
  51.       POP CX          {restore count for outer loop}
  52.     LOOP @PatLoop
  53.     POP DS
  54.     @Out:
  55.   END;
  56.  
  57.   PROCEDURE FillPattOthr(VAR Dest, Patt; Count,
  58.               Siz : Word); Assembler;
  59.   ASM
  60.     MOV CX, Siz
  61.     JCXZ @Out
  62.     XCHG CX, DX     {size of pattern in DX}
  63.     MOV CX, Count   {count in CX}
  64.     JCXZ @Out
  65.     PUSH DS
  66.     LES DI, Dest    {ES:DI points to destination}
  67.     LDS SI, Patt    {DS:SI points to pattern}
  68.     MOV BX, SI      {save SI in BX}
  69.     CLD             {forward direction}
  70.     @PatLoop:
  71.       PUSH CX         {save count for outer loop}
  72.       MOV CX, DX      {put inner count in CX}
  73.       MOV SI, BX      {DS:SI points to source}
  74.       @TheLoop:
  75.         LODSB         {get a byte from pattern..}
  76.         STOSB         {.. and store in destination}
  77.         INC DI        {skip a byte}
  78.       LOOP @TheLoop
  79.       POP CX          {restore count for outer loop}
  80.     LOOP @PatLoop
  81.     POP DS
  82.     @Out:
  83.   END;
  84.  
  85. END.